package com.example.configure;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

  @Value("${spring.application.name}")
  private String applicationName;

  @Bean
  public Docket api1() {
    return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo()).groupName(applicationName)
        .select()
        .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
        .build();
  }

  private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
        .title("pulsar-example端服务 APIs")
        .version("2.0")
        .build();
  }
}
